﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Simple.Contracts.Enums.Common;
using SKIT.FlurlHttpClient.Wechat.Api;

namespace Simple.WebAi.Extensions
{
    /// <summary>
    /// 微信接入扩展
    /// </summary>
    public static class WeixinExtensions
    {
        /// <summary>
        /// 框架扩展：注册使用服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static void AddWechatApiClient(this IServiceCollection services)
        {
            var configuration = services.BuildServiceProvider().GetService<IConfiguration>()!;
            var weChatAppClientDic = new Dictionary<WeChatAppClientEnum, WechatApiClient>();

            // 添加恩睦照护WechatApiClient
            var amosZhaoHuWechatApiClient = WechatApiClientBuilder.Create(new WechatApiClientOptions()
            {
                AppId = configuration!["WechatApp:AmosZhaoHuIot:AppId"]!,
                AppSecret = configuration!["WechatApp:AmosZhaoHuIot:AppSecret"]!
            }).Build();
            weChatAppClientDic.Add(WeChatAppClientEnum.AmosZhaoHuWechatApiClient, amosZhaoHuWechatApiClient);

            // 添加到IOC容器
            services.AddSingleton<Dictionary<WeChatAppClientEnum, WechatApiClient>>(weChatAppClientDic);
        }
    }
}
